﻿
using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DotNetNuke.Entities.Content;
using DotNetNuke.Entities.Content.Common;

namespace DotNetNuke.Modules.TaskManager.Components.Taxonomy
{
    public class Terms
    {
        public void ManageTaskTerms(Task objTask, ContentItem objContent)
        {

            string filename = @"C:\Users\Jeff McVey\Desktop\Terms.txt";
            FileStream traceLog = new FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
            TextWriterTraceListener listener = new TextWriterTraceListener(traceLog);
            listener.WriteLine("Terms File Opened *****************");

            // output to listener 
            listener.WriteLine("Term objContent.ContentItemId 1: " + objContent.ContentItemId.ToString());
            

            RemoveTaskTerms(objContent);

            // output to listener 
            listener.WriteLine("Term objContent.ContentItemId 2: " + objContent.ContentItemId.ToString());   

            foreach(var term in objTask.Terms)
            {
                Util.GetTermController().AddTermToContent(term,objContent);
            }

            // output to listener 
            listener.WriteLine("Term objContent.ContentItemId 3: " + objContent.ContentItemId.ToString());
            // flush any open output before termination
            // maybe in an override of Form.OnClosed 
            listener.Flush();
            listener.Close();
        }

        public void RemoveTaskTerms(ContentItem objContent)
        {
            Util.GetTermController().RemoveTermsFromContent(objContent);                      
        }
    }
}

